package cn.com.fuhuitong.main.home.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import cn.com.fuhuitong.app.BaseApplication
import cn.com.fuhuitong.base.BaseViewModel
import cn.com.fuhuitong.base.SafeMutableLiveData
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.HttpResponse
import cn.com.fuhuitong.http.ViewModelSubscribeListener
import cn.com.fuhuitong.main.home.entity.*
import cn.com.fuhuitong.main.home.mode.HomeManager
import io.reactivex.disposables.Disposable

class CaseViewModel(application: Application) : BaseViewModel(application) {

    private val homeManager: HomeManager = HomeManager()

    val caseListDataLiveData = MutableLiveData<HttpResponse<CaseListResponse>>()

    val categoryTwoLiveData = MutableLiveData<HttpResponse<CategoryTwoResponse>>()


    private var page: Int = 1
    private var limit: Int = 100

    /**
     * 获取公益慈善列表
     */
    fun caseIndex(type: Int) {
        val listener =
            object : ViewModelSubscribeListener<CaseListResponse>(caseListDataLiveData) {}
        val caseIndexDisposable: Disposable = homeManager.caseIndex(
            type.toString(), page.toString(), limit.toString(), listener
        )
        dispose.add(caseIndexDisposable)
    }

    fun caseIndex(homeIconId: Int,twoHomeIconId: Int) {
        val listener =
            object : ViewModelSubscribeListener<CaseListResponse>(caseListDataLiveData) {}
        val caseIndexDisposable: Disposable = homeManager.caseIndex(
            homeIconId.toString(), twoHomeIconId.toString(),page.toString(), limit.toString(), listener
        )
        dispose.add(caseIndexDisposable)
    }

    fun indexGetTwoHomeGoods(id: Int) {
        val listener =
            object : ViewModelSubscribeListener<CategoryTwoResponse>(categoryTwoLiveData) {}
        val caseIndexDisposable: Disposable = homeManager.indexGetTwoHomeGoods(
            BaseApplication.userToken(), id.toString(), listener
        )
        dispose.add(caseIndexDisposable)
    }

    /**
     * 获取公益慈善列表
     */
    fun caseChairIndex(type: Int) {
        val listener =
            object : ViewModelSubscribeListener<CaseListResponse>(caseListDataLiveData) {}
        val caseIndexDisposable: Disposable = homeManager.caseChairIndex(
            type.toString(), page.toString(), limit.toString(), listener
        )
        dispose.add(caseIndexDisposable)
    }
}